package com.bsj.power.system.web;

import com.bsj.power.common.config.exception.ApiException;
import com.bsj.power.common.config.global.JsonResult;
import com.bsj.power.common.config.global.JsonResultEnum;
import com.bsj.power.common.def.dto.PageDTO;
import com.bsj.power.common.def.entity.ai.AiAlarm;
import com.bsj.power.common.def.dto.ai.AiAlarmDTO;
import com.bsj.power.common.def.vo.web.system.ai.AnnexStatVO;
import com.bsj.power.system.service.AiAlarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yinhao
 * @version 1.0
 * @description 系统AI报警附件
 * @date 2024/6/26
 */
@RestController
@RequestMapping("/system/ai/annex")
public class SysAiAnnexController {

    @Autowired
    private AiAlarmService aiAlarmService;

    /**
     * 新增AI报警附件
     *
     * @param dto
     * @return
     */
    @PostMapping("/addAndUpdateAi")
    public JsonResult<Integer> addAndUpdateAi(@RequestBody AiAlarmDTO dto) {
        return JsonResult.success(aiAlarmService.addAndUpdateAi(dto));
    }

    /**
     * 分页获取AI报警附件列表
     * @param dto
     * @param alarmName
     * @return
     */
    @GetMapping("/doAiAnnexPageList")
    public JsonResult<List<AiAlarm>> doAiAnnexPageList(PageDTO dto, String alarmName) {
        return aiAlarmService.pageList(dto, alarmName);
    }

    /**
     * 删除AI报警附件
     * @param aiId
     * @return
     */
    @GetMapping("/doDeleteAiAnnex")
    public JsonResult<Integer> doDeleteAiAnnex(Long aiId) {
        if (aiId == null) {
            throw new ApiException(JsonResultEnum.PARAM_ERROR);
        }
        return JsonResult.success(aiAlarmService.deleteAiAnnex(aiId));
    }

    /**
     * 附件数据分析统计
     * @param startTime
     * @param endTime
     * @return
     */
    @GetMapping("/doAnalysisAiAnnex")
    public JsonResult<AnnexStatVO> doAnalysisAiAnnex(String startTime, String endTime) {
        return JsonResult.success(aiAlarmService.analysisAiAnnex(startTime, endTime));
    }
}
